<?php 

/*
 *------------------------------------------------------------------------------
 * Project Name  : e-Synergy Library System
 *         Code  : ESN-LBS
 *
 * Created By    : Junlapong
 *         Date  : 2010/01/21
 *
 * $Id$
 *------------------------------------------------------------------------------
 *    copyright: e-Synergy Co., Ltd.
 *==============================================================================
 */

if ( ! defined('BASEPATH')) exit('No direct script access allowed');

/**
 * @author Junlapong
 *
 */
class MY_Loader extends CI_Loader
{
	
	var $_ci_entities			= array();
	
	/* 
	 * add clear_cache optional
	 * 
	 * @see system/libraries/CI_Loader#view($view, $vars, $return)
	 */
	function view($view, $vars = array(), $return = FALSE, $no_cache = TRUE)
	{
		if ($no_cache === TRUE)
		{
			header('Expires: Sat, 26 Jul 1997 05:00:00 GMT');
			header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
			header('Cache-Control: no-store, no-cache, must-revalidate');
			header('Cache-Control: post-check=0, pre-check=0');
			header('Pragma: no-cache');
		}
		
		return $this->_ci_load(array(  '_ci_view' => $view
		                             , '_ci_vars' => $this->_ci_object_to_array($vars)
		                             , '_ci_return' => $return)
		                            );
	}
	
	/**
	 *
	 * This function lets users load and instantiate classes.
	 * It is designed to be called from a user's app controllers.
	 *
	 * @access	public
	 * @param	mixed	the name of the entitt or array of entities
	 * @return	void
	 */	
	function entity($entity = '')
	{
		if (is_array($entity))
		{
			foreach ($entity as $class)
			{
				$this->_ci_load_entity($class);
			}
		}
		else
		{
			$this->_ci_load_entity($entity);
		}		
	}
	
	function _ci_load_entity($name)
	{
		if (in_array($name, $this->_ci_entities, TRUE))
		{
			return;
		}
		
		if (! file_exists(APPPATH . 'models/entities/' . $name . EXT))
		{
			show_error('Unable to locate the entity you have specified: ' . $name);
		}
		
		require_once(APPPATH . 'models/entities/' . $name . EXT);		
		$this->_ci_entities[] = $name;
	}
}
// END MY_Loader class

/* End of file MY_Loader.php */
/* Location: application/libraries/MY_Loader.php */